﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dtos;
using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class DepartmentBll:IDepartmentBll
    {
        public IDepartmentDal _d;
        public DepartmentBll(IDepartmentDal d)
        {
            _d = d;
        }
        public async Task<int> AddDepartmentAsync(string title)
        {
            return await _d.AddAsync(new Model.Department
            {
                title = title
            });
        }
        public async Task<int> DeleteDepartmentAsync(Guid id)
        {
            var data = await _d.GetIdAll(id);
            if (data != null)
                return await _d.DeleteAsync(data);
            return 0;
        }
        public async Task<int> EditDepartmentAsync(Guid id, string title)
        {
            var data = await _d.GetIdAll(id);
            if (data == null)
                return 0;
            data.title = title;
            data.UpdateTime = DateTime.Now;
            return await _d.UpdateAsync(data);
        }
        public async Task<List<Department>> getAllDepartment()
        {
            var data = await _d.GetAll();
            return data.Select(m => new Department
            {
                Id = m.Id,
                title = m.title,
                UpdateTime = m.UpdateTime,
            }).ToList();
        }
        public Task<DepartmentDtos> GetDepartmentIdAsync(Guid id)
        {
            throw new NotImplementedException();
        }
        public Task<bool> IsExistsAsync(string title)
        {
            throw new NotImplementedException();
        }

      
        }
    }

